package com.cssnj.portal.web.comm;

import io.predictech.framework.utility.StringUtil;
import io.predictech.framework.web.common.WebHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 用于接入功能打开页面
 *
 * @author Arthur
 * @version 1.0
 * @since 2018-9-21 16:41
 */
@Controller
@RequestMapping(value = "/forward")
public class ForwardController {
    /**
     * @param request 需要包含参数 : funcId 功能ID
     *                funcName 功能名称
     *                isPage 是否新页打开  0 否 1 是
     *                forwardUrl 跳转链接
     * @description 接入功能跳转
     * @author Arthur
     * @since 2018-9-21 16:45
     **/
    @RequestMapping(value = "/forward.do")
    public ModelAndView forward(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> paramsMap = WebHelper.getParamFromRequest(request);
        if (null == paramsMap.get("funcId") || null == paramsMap.get("isTab") || null == paramsMap.get("forwardUrl") || null == paramsMap.get("funcName"))
            response.setStatus(403);
        else
            paramsMap.put("forwardUrl", StringUtil.castBase64ToStr(StringUtil.castBase64ToStr(String.valueOf(paramsMap.get("forwardUrl")))));
        return new ModelAndView("forward/forward").addAllObjects(paramsMap);
    }
}
